<template>
	<div style="padding:0px;">
		<el-card class="box-card">
		  <!-- <div slot="header" class="clearfix">
		    <span style="line-height: 30px;"></span>
		  </div> -->
		  <div  class="text item" >
			  <el-form :model="dialogForm" ref="dialogForm" :label-width="formLabelWidth">
			  	<el-form-item label="角色名"  prop="qcsl">
			      <el-input v-model="dialogSendData.data.roleName" type="tel" auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
			    </el-form-item>
			    <!-- <el-form-item label="权限"  prop="qcsl">
			        <el-checkbox-group v-model="dialogForm.type">
			    				      <el-checkbox label="美食/餐厅线上活动" name="type"></el-checkbox>
			    				      <el-checkbox label="地推活动" name="type"></el-checkbox>
			    				      <el-checkbox label="线下主题活动" name="type"></el-checkbox>
			    				      <el-checkbox label="单纯品牌曝光" name="type"></el-checkbox>
			    				    </el-checkbox-group>
			    </el-form-item> -->
			    <el-form-item label="权限key"  prop="qcsl">
			    	<el-input v-model="dialogSendData.data.roleKey"  auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
			    </el-form-item>
			    <el-form-item label="备注"  prop="qcsl">
			      <el-input type="textarea" :rows=3 v-model="dialogSendData.data.remark"  auto-complete="off" :disabled="!dialogSendData.isAdd"></el-input>
			    </el-form-item>
			    
			  </el-form>
			</div>
		</el-card>
				
		<div  style="text-align:right;margin-top:15px;">
			 <el-button @click="returnBack">返 回</el-button>
			 <el-button type="primary" @click="submitConfirmForm('dialogForm')">提 交</el-button>
		</div>
	</div>
</template>
<script>
    import agentHttp from '@/utils/agentHttp.js'
	export default{
		components:{},
		created(){		 
			if(this.dialogSendData.data != null){ 
	      		this.$emit('refreshSeachData');  
	      	}
        },

        updated(){
        },
		props:['dialogSendData','tableData'],
		data(){
			return{
				formLabelWidth:'170px',
				//弹窗或者查看页面信息
		         dialogForm:{
		          imagUrl:[],   //七牛图片地址
		          activityTheme:"",
		          linkUrl:""
		         
		        },
		        //验证规则
		        rules: {
		          tg_btg: [
		            { required: true, message: '请选择是否通过', trigger: 'change' }
		           /* ,{ min: 3, max: 5, message: '长度在 3 到 5 个字符', trigger: 'blur' }*/
		          ],
		          bz:[
		            {required: true, message: '请填写备注信息', trigger: 'blur'}
		          ]
		        }
			}
		},methods:{
			returnBack(){
				this.dialogSendData.dialogFormVisible=false;
			},
			submitConfirmForm(formName){
                this.$refs[formName].validate((valid) => {
		          if (valid) {
		          	if(this.dialogSendData.data.id != null){
		          		//修改
		          		this.editData();
		          		
		          	}else{
		          		//添加
		          	    this.addData(); 
		          	}
		          	// setTimeout(()=>{
		          	// 	this.dialogSendData.dialogFormVisible=false;
		          	// },500)
		          } else {
		            console.log('error submit!!');
		            return false;
		          }
		        });
			}, 
		    addData(){ 
		        agentHttp.postJson('adminApi/admin/sys_role/add',this.dialogSendData.data).then((data)=>{
		            if(data.success){  
		            	this.$emit('refreshSeachData', null); 
		            	this.$message.success(data.data);
		            	this.dialogSendData.dialogFormVisible=false;
		            } 
		        }) 
		    },
		    editData(){ 
		        agentHttp.putJson('adminApi/admin/sys_role/update',this.dialogSendData.data).then((data)=>{
		            if(data.success){  
		            	this.$emit('refreshSeachData', null); 
		            	this.$message.success(data.data);
		            	this.dialogSendData.dialogFormVisible=false;
		            } 
		        }) 
		    },
		    // selectData(){
		    // 	//console.log('取消下方注释，修改请求地址')
		    //     agentHttp.get('adminApi/admin/carousel/select_carousel/'+this.dialogSendData.id).then((data)=>{	
		    //         if(data.success){  
		    //         	this.dialogForm=data.data;
		    //         	this.$set(this.dialogForm,'type',[]);
		            	
		    //         } 
		    //     }) 
		    // } 

		}
	}
</script>
